package multithread.interrupt;

/**
 * Created by xi on 2019/2/17.
 * 问题一:syn的方法能被中断吗
 *
 */
public class SynchronizedDefect {
    private static final Object o1 = new Object();
    private static final Object o2 = new Object();

    public static void main(String[] args) throws InterruptedException {
        t1.start();
        System.out.println("before interrupt");
        t1.interrupt();
        t1.join();
        System.out.println("end interrupt");
    }

    //syn如果里面没有sleep,wait的代码，不能检测到异常Interupt异常
    static Thread t1 = new Thread(() -> {
        synchronized (o1){
            try {
                System.out.println("start t1");
               // Thread.sleep(10000);
                while (true){

                }
            } catch (Exception e) {
                System.out.println("t1 interrupted");
            }
       }
    });

}
